package com.lincoln.cloud.servercenter.bean;

import com.lincoln.cloud.common.bean.ServerMessage;
import com.lincoln.cloud.servercenter.interfaces.Verify;

/**
 * 消息统一处理
 *
 * @author lincoln
 */
public class ServerMessageExecuter {
    /**
     * 接收到新消息时
     *
     * @return
     */
    public static boolean newMessage() {
        //存在验证规则
        if (ServerCenterContext.serverCenterBean().getVerifies() != null && ServerCenterContext.serverCenterBean().getVerifies().size() > 0) {
            for (Verify verify : ServerCenterContext.serverCenterBean().getVerifies()) {
                boolean flag;
                try {
                    flag = verify.verify();
                } catch (Exception e) {
                    flag = false;
                }
                if (flag) {
                    try {
                        verify.execute();
                    } catch (Exception e) {

                    }
                }
            }
        }
        return true;
    }

    /**
     * 发送消息
     *
     * @return
     */
    public static boolean sendMessage(ServerMessage serverMessage) {
        return ServerCenterContext.serverPool().sendServerMessage(serverMessage);
    }
}
